import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:"/login"
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },{
    path: '/home',
    name: 'Home',
    component: Home
  }
 
]
this.router.beforeEach((to, from, next) => {
  // to and from are both route objects. must call `next`.
  if(to.path==='/login') return next()
  const token= this.setLocalValue('token',res.data.token)
  if(!token) return next('/login')
  next()

})
const router = new VueRouter({
  routes
})

export default router
